using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using SJXmlP.XMLClasses;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using O;
using 修为尽失.辅助;
using 修为尽失.辅助.exts;

namespace yW5Lib
{
    public abstract class clsSceneBase : clsBase
    {
        public bool ShowDebugMessage = false;
        public bool AddedToProject;

        internal bool UpdateCount;

        internal string mvarPlainText;

        internal DateTime LastConvertedToPlain;

        internal bool RTFNeedsSaving;

        internal DateTime mvarLastUpdated;

        internal int mvarVersion;

        internal bool mvarEditingExternal;

        internal int mvarBelongsToChID;

        internal bool mvarV6;

        internal string mvarConflict;

        internal string mvarGoal;

        internal string mvarOutcome;

        internal int mvarMinute;

        internal int mvarHour;

        internal int mvarDay;

        internal int mvarLastsMinutes;

        internal int mvarLastsHours;

        internal int mvarLastsDays;

        internal bool mvarExportCondSpecific;

        internal bool mvarExportWhenRTF;

        internal bool mvarExportWhenRTFChapters;

        internal bool mvarExportWhenHTML;

        internal bool mvarExportWhenText;

        internal bool mvarExportWhenLaTeX;

        internal int[] mvarField;

        internal bool mvarReactionScene;

        internal bool mvarSubplot;

        internal int mvarStatus;

        internal int mvarWordCount;

        internal int mvarLetterCount;

        internal string mvarRTFFile;

        internal bool mvarLocked;

        public bool SpecificDateMode;

        public DateTime SpecificDateTime;

        internal bool mvarAppendToPrevious;

        internal clsCollection<int> CharIDs;

        internal clsCollection<int> LocIDs;

        internal clsCollection<int> ItemIDs;

        public bool ContainsYW2Code;

        public const string ObjectName = "Scene";

        public abstract string TextRTF { get; set; }

        public bool V6
        {
            get { return mvarV6; }
            set { mvarV6 = value; }
        }

        public bool AppendToPrevious
        {
            get { return mvarAppendToPrevious; }
            set { mvarAppendToPrevious = value; }
        }

        public bool ReactionScene
        {
            get { return mvarReactionScene; }
            set { mvarReactionScene = value; }
        }

        public bool SubPlot
        {
            get { return mvarSubplot; }
            set { mvarSubplot = value; }
        }

        public string RTFFilename
        {
            get
            {
                if (!mvarV6)
                {
                    return mvarRTFFile;
                }

                return "Ch" + Conversions.ToString(BelongsToChID) + "_Sc" + Conversions.ToString(ID) + ".rtf";
            }
        }

        public bool Locked => mvarLocked;

        public bool EditingExternal => mvarEditingExternal;

        public DateTime StartDate => new DateTime(0, 0, Day_Renamed, Hour_Renamed, Minute_Renamed, 0);

        public int Minute_Renamed
        {
            get { return mvarMinute; }
            set { mvarMinute = value; }
        }

        public int Hour_Renamed
        {
            get { return mvarHour; }
            set { mvarHour = value; }
        }

        public int Day_Renamed
        {
            get { return mvarDay; }
            set { mvarDay = value; }
        }

        public int LastsMinutes
        {
            get { return mvarLastsMinutes; }
            set { mvarLastsMinutes = value; }
        }

        public int LastsHours
        {
            get { return mvarLastsHours; }
            set { mvarLastsHours = value; }
        }

        public int LastsDays
        {
            get { return mvarLastsDays; }
            set { mvarLastsDays = value; }
        }

        public bool ExportCondSpecific
        {
            get { return mvarExportCondSpecific; }
            set { mvarExportCondSpecific = value; }
        }

        public bool ExportWhenRTF
        {
            get { return mvarExportWhenRTF; }
            set { mvarExportWhenRTF = value; }
        }

        public bool ExportWhenRTFChapters
        {
            get { return mvarExportWhenRTFChapters; }
            set { mvarExportWhenRTFChapters = value; }
        }

        public bool ExportWhenHTML
        {
            get { return mvarExportWhenHTML; }
            set { mvarExportWhenHTML = value; }
        }

        public bool ExportWhenText
        {
            get { return mvarExportWhenText; }
            set { mvarExportWhenText = value; }
        }

        public bool ExportWhenLaTeX
        {
            get { return mvarExportWhenLaTeX; }
            set { mvarExportWhenLaTeX = value; }
        }

        public string Outcome
        {
            get { return mvarOutcome; }
            set { mvarOutcome = value; }
        }

        public string Conflict
        {
            get { return mvarConflict; }
            set { mvarConflict = value; }
        }

        public string Goal
        {
            get { return mvarGoal; }
            set { mvarGoal = value; }
        }

        public int get_Field(int Index)
        {
            return this.mvarField[Index];
        }

        public void set_Field(int Index, int Value)
        {
            this.mvarField[Index] = Value;
        }

        public int Status
        {
            get { return mvarStatus; }
            set { mvarStatus = value; }
        }

        public int BelongsToChID
        {
            get { return mvarBelongsToChID; }
            set { mvarBelongsToChID = value; }
        }

        public int Wordcount
        {
            get
            {
                if (UpdateCount)
                {
                    DoCount();
                    UpdateCount = false;
                }

                return mvarWordCount;
            }
        }

        public int Lettercount
        {
            get
            {
                if (UpdateCount)
                {
                    DoCount();
                    UpdateCount = false;
                }

                return mvarLetterCount;
            }
        }

        public O.Counter.字词数目统计结果 字词数目统计 { get; private set; }
        public int CharCount => CharIDs.Count();

        public int ViewPointID
        {
            get
            {
                if (CharCount == 0)
                {
                    return 0;
                }

                return CharIDs[1];
            }
        }

        public DateTime Lastupdated => mvarLastUpdated;

        public int get_CharIDByIndex(int Index)
        {
            int num;
            try
            {
                num = this.CharIDs[Index];
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                num = -1;
                ProjectData.ClearProjectError();
            }

            return num;
        }

        public int LocationCount => LocIDs.Count();

        public int get_LocationID(int Index)
        {
            return Index > this.LocIDs.Count() ? -1 : this.LocIDs[Index];
        }

        public int get_ItemID(int Index)
        {
            return Index > this.ItemIDs.Count() ? -1 : this.ItemIDs[Index];
        }

        public int get_CharID(int Index)
        {
            return Index > this.CharIDs.Count() ? -1 : this.CharIDs[Index];
        }

        public int get_LocationIDByIndex(int Index)
        {
            return this.get_LocationID(Index);
        }

        public int ItemCount
        {
            get { return this.ItemIDs.Count(); }
        }

        public int get_ItemIDByIndex(int Index)
        {
            return this.get_ItemID(Index);
        }

        protected clsSceneBase()
        {
            mvarPlainText = "";
            mvarConflict = "";
            mvarGoal = "";
            mvarOutcome = "";
            mvarField = new int[6];
            mvarStatus = 1;
            mvarRTFFile = "";
            CharIDs = new clsCollection<int>();
            LocIDs = new clsCollection<int>();
            ItemIDs = new clsCollection<int>();
        }

        internal abstract void ConvertToPlainIfNec();

        internal abstract string MarkedUpTextV6Only();

        public abstract void SetMarkup(string strMarkup);

        public void MarkExternalEditing()
        {
            mvarEditingExternal = true;
            mvarLocked = true;
        }

        public void MarkNotExternalEditing()
        {
            mvarEditingExternal = false;
            mvarLocked = false;
        }

        public void OverrideWordcount(int NewCount)
        {
            mvarWordCount = NewCount;
            mvarLetterCount = NewCount;
        }

        public void MarkUpdated(DateTime UpdateTime)
        {
            mvarLastUpdated = UpdateTime;
        }

        public int ForceWordcount()
        {
            UpdateCount = true;
            return Wordcount;
        }

        public string ConvertedToPlainText()
        {
            ConvertToPlainIfNec();
            return mvarPlainText;
        }

        public void RemoveCharByID(int ID)
        {
            if (CharIDs.Contains(ID))
            {
                CharIDs.Remove(Conversions.ToString(ID));
            }
        }

        public void AddCharByID(int ID)
        {
            if (!CharIDs.Contains(ID))
            {
                CharIDs.Add(ID, Conversions.ToString(ID));
            }
        }

        public void AddLocationByID(int ID)
        {
            if (!LocIDs.Contains(Conversions.ToString(ID)))
            {
                LocIDs.Add(ID, Conversions.ToString(ID));
            }
        }

        public void RemoveLocationByID(int ID)
        {
            if (LocIDs.Contains(Conversions.ToString(ID)))
            {
                LocIDs.Remove(Conversions.ToString(ID));
            }
        }

        public void AddItemByID(int ID)
        {
            if (!ItemIDs.Contains(Conversions.ToString(ID)))
            {
                ItemIDs.Add(ID, Conversions.ToString(ID));
            }
        }

        public void RemoveItemByID(int ID)
        {
            if (ItemIDs.Contains(Conversions.ToString(ID)))
            {
                ItemIDs.Remove(Conversions.ToString(ID));
            }
            else
            {
                clsShared.cLog.AddAction("Tried to remove item ID " + Conversions.ToString(ID) +
                                         " but it's not in the project.");
            }
        }

        public virtual void Clear()
        {
            BaseClear();
            mvarLocked = false;
            CharIDs.Clear();
            LocIDs.Clear();
            ItemIDs.Clear();
            mvarRTFFile = "";
            RTFNeedsSaving = false;
            mvarPlainText = "";
            ContainsYW2Code = false;
            UpdateCount = true;
        }

        public void ClearRTFFilename()
        {
            mvarRTFFile = "";
        }

        public void Unlock()
        {
            mvarLocked = false;
        }

        public void Lock()
        {
            mvarLocked = true;
        }

        public void ChangeViewpointByID(int NewViewpointID)
        {
            try
            {
                if (CharIDs.Count() > 0 && NewViewpointID > 0)
                {
                    RemoveCharByID(NewViewpointID);
                }

                if (CharIDs.Count() == 0)
                {
                    if (NewViewpointID > 0)
                    {
                        CharIDs.Add(NewViewpointID, Conversions.ToString(NewViewpointID));
                    }
                }
                else
                {
                    CharIDs.Add(NewViewpointID, Conversions.ToString(NewViewpointID), 1);
                }

                TriggerSaveEvent();
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                Exception ex2 = ex;
                ProjectData.ClearProjectError();
            }
        }

        public void SetViewpointByID(int NewViewpointID)
        {
            try
            {
                if (NewViewpointID > 0)
                {
                    if (CharCount > 0)
                    {
                        CharIDs.Remove(1);
                    }

                    if (CharCount > 0)
                    {
                        RemoveCharByID(NewViewpointID);
                    }

                    if (CharCount == 0)
                    {
                        if (NewViewpointID > 0)
                        {
                            CharIDs.Add(NewViewpointID, Conversions.ToString(NewViewpointID));
                        }
                    }
                    else
                    {
                        CharIDs.Add(NewViewpointID, Conversions.ToString(NewViewpointID), 1);
                    }
                }
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                Exception ex2 = ex;
                ProjectData.ClearProjectError();
            }
        }

        public void DoCount()
        {
            ConvertToPlainIfNec();
            mvarWordCount = clsShared.cText.Wordcount(mvarPlainText, true);
            mvarLetterCount = mvarPlainText.Length;
            字词数目统计 = Counter.统计文本字词(mvarPlainText);
            if (ShowDebugMessage)
            {
                if (字词数目统计.字符数 > 0)
                {
                    Interaction.MsgBox($"{字词数目统计.ToString()}\n\n耗时：{字词数目统计.统计耗时}毫秒", Title: "字词数目统计结果");
                }

                var tuple = Counter.字词统计器.字符数典(mvarPlainText);
                if (tuple.Item1.Count > 1)
                {
                    //var a = tuple.Item1.ToPrintableString().Substring(0,500);
                    var a = Json.Write(tuple.Item1.OrderByDescending(x => x.Value).ToList(), true);
                    Interaction.MsgBox($"{a}\n\n耗时：{tuple.Item2}毫秒", Title: "字符数典");
                }
            }
        }

        public string DataAsXML(bool IncludingRTF)
        {
            string result = "";
            try
            {
                StringBuilder stringBuilder = new StringBuilder();
                string text = "\t\t";
                string value = "\t\t\t";
                stringBuilder.AppendLine("\t<SCENE>");
                stringBuilder.Append(BaseDataAsXML());
                string value2;
                if (mvarV6)
                {
                    value2 = text + cXml.EncloseBool(mvarV6, "V6");
                    stringBuilder.AppendLine(value2);
                }

                if (mvarOutcome.Length > 0)
                {
                    value2 = text + cXml.EncloseCData(mvarOutcome, "Outcome");
                    stringBuilder.AppendLine(value2);
                }

                if (mvarGoal.Length > 0)
                {
                    value2 = text + cXml.EncloseCData(mvarGoal, "<Goal>", "</Goal>");
                    stringBuilder.AppendLine(value2);
                }

                if (mvarConflict.Length > 0)
                {
                    value2 = text + cXml.EncloseCData(mvarConflict, "<Conflict>", "</Conflict>");
                    stringBuilder.AppendLine(value2);
                }

                if (!mvarV6 && mvarRTFFile.Length > 0)
                {
                    value2 = text + cXml.EncloseCData(mvarRTFFile, "<RTFFile>", "</RTFFile>");
                    stringBuilder.AppendLine(value2);
                }

                value2 = text + cXml.EncloseInt(mvarBelongsToChID, "<BelongsToChID>", "</BelongsToChID>");
                stringBuilder.AppendLine(value2);
                if (mvarMinute != 0)
                {
                    value2 = text + cXml.EncloseInt(mvarMinute, "<Minute>", "</Minute>");
                    stringBuilder.AppendLine(value2);
                }

                if (mvarHour != 0)
                {
                    value2 = text + cXml.EncloseInt(mvarHour, "<Hour>", "</Hour>");
                    stringBuilder.AppendLine(value2);
                }

                if (mvarDay != 0)
                {
                    value2 = text + cXml.EncloseInt(mvarDay, "<Day>", "</Day>");
                    stringBuilder.AppendLine(value2);
                }

                if (SpecificDateMode)
                {
                    stringBuilder.AppendLine(text + cXml.EncloseBool(SpecificDateMode, "<SpecificDateMode>",
                                                 "</SpecificDateMode>"));
                }

                if (SpecificDateMode)
                {
                    stringBuilder.AppendLine(text + cXml.EncloseDate(SpecificDateTime, "<SpecificDateTime>",
                                                 "</SpecificDateTime>"));
                }

                if (mvarLastsMinutes != 0)
                {
                    value2 = text + cXml.EncloseInt(mvarLastsMinutes, "<LastsMinutes>", "</LastsMinutes>");
                    stringBuilder.AppendLine(value2);
                }

                if (mvarLastsHours != 0)
                {
                    value2 = text + cXml.EncloseInt(mvarLastsHours, "<LastsHours>", "</LastsHours>");
                    stringBuilder.AppendLine(value2);
                }

                if (mvarLastsDays != 0)
                {
                    value2 = text + cXml.EncloseInt(mvarLastsDays, "<LastsDays>", "</LastsDays>");
                    stringBuilder.AppendLine(value2);
                }

                if (mvarExportCondSpecific)
                {
                    value2 = text + cXml.EncloseBool(mvarExportCondSpecific, "<ExportCondSpecific>",
                                 "</ExportCondSpecific>");
                    stringBuilder.AppendLine(value2);
                }

                if (mvarExportWhenRTF)
                {
                    value2 = text + cXml.EncloseBool(mvarExportWhenRTF, "ExportWhenRTF");
                    stringBuilder.AppendLine(value2);
                }

                if (mvarExportWhenRTFChapters)
                {
                    value2 = text + cXml.EncloseBool(mvarExportWhenRTFChapters, "ExportWhenRTFChapters");
                    stringBuilder.AppendLine(value2);
                }

                if (mvarExportWhenHTML)
                {
                    value2 = text + cXml.EncloseBool(mvarExportWhenHTML, "<ExportWhenHTML>", "</ExportWhenHTML>");
                    stringBuilder.AppendLine(value2);
                }

                if (mvarExportWhenText)
                {
                    value2 = text + cXml.EncloseBool(mvarExportWhenText, "<ExportWhenText>", "</ExportWhenText>");
                    stringBuilder.AppendLine(value2);
                }

                if (mvarExportWhenLaTeX)
                {
                    value2 = text + cXml.EncloseBool(mvarExportWhenLaTeX, "<ExportWhenLaTeX>", "</ExportWhenLaTeX>");
                    stringBuilder.AppendLine(value2);
                }

                int num = 1;
                do
                {
                    if (mvarField[num] == 0)
                    {
                        mvarField[num] = 1;
                    }

                    value2 = text + cXml.EncloseInt(mvarField[num], "<Field" + Conversions.ToString(num) + ">",
                                 "</Field" + Conversions.ToString(num) + ">");
                    stringBuilder.AppendLine(value2);
                    num++;
                } while (num <= 4);

                if (mvarReactionScene)
                {
                    value2 = text + cXml.EncloseBool(mvarReactionScene, "<ReactionScene>", "</ReactionScene>");
                    stringBuilder.AppendLine(value2);
                }

                if (mvarSubplot)
                {
                    value2 = text + cXml.EncloseBool(mvarSubplot, "<SubPlot>", "</SubPlot>");
                    stringBuilder.AppendLine(value2);
                }

                if (mvarAppendToPrevious)
                {
                    value2 = text + cXml.EncloseBool(mvarAppendToPrevious, "AppendToPrev");
                    stringBuilder.AppendLine(value2);
                }

                value2 = text + cXml.EncloseInt(mvarStatus, "Status");
                stringBuilder.AppendLine(value2);
                value2 = text + cXml.EncloseInt(mvarWordCount, "WordCount");
                stringBuilder.AppendLine(value2);
                value2 = text + cXml.EncloseInt(mvarLetterCount, "LetterCount");
                stringBuilder.AppendLine(value2);
                value2 = text + "<Characters>";
                stringBuilder.AppendLine(value2);
                int num2 = CharIDs.Count();
                for (num = 1; num <= num2; num++)
                {
                    value2 = text + "\t" + cXml.EncloseInt(CharIDs[num], "CharID");
                    stringBuilder.AppendLine(value2);
                }

                value2 = text + "</Characters>";
                stringBuilder.AppendLine(value2);
                value2 = text + "<Locations>";
                stringBuilder.AppendLine(value2);
                int num3 = LocIDs.Count();
                for (num = 1; num <= num3; num++)
                {
                    value2 = text + "\t" + cXml.EncloseInt(LocIDs[num], "LocID");
                    stringBuilder.AppendLine(value2);
                }

                value2 = text + "</Locations>";
                stringBuilder.AppendLine(value2);
                stringBuilder.AppendLine(text + "<Items>");
                int num4 = ItemIDs.Count();
                for (num = 1; num <= num4; num++)
                {
                    stringBuilder.Append(value);
                    stringBuilder.AppendLine(cXml.EncloseInt(ItemIDs[num], "ItemID"));
                }

                stringBuilder.AppendLine(text + "</Items>");
                if (mvarV6)
                {
                    stringBuilder.Append(text);
                    stringBuilder.AppendLine(cXml.EncloseCData(MarkedUpTextV6Only(), "SceneContent"));
                }
                else if (IncludingRTF)
                {
                    stringBuilder.Append(text);
                    clsShared.cLog.AddAction("If saving as YW6, this line should not be in the log");
                    stringBuilder.AppendLine(cXml.EncloseCData(TextRTF, "EMBEDDEDRTF"));
                }

                stringBuilder.AppendLine("\t</SCENE>");
                result = stringBuilder.ToString();
                return result;
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                Exception ex2 = ex;
                clsShared.cLog.AddAction(ex2, MethodBase.GetCurrentMethod());
                ProjectData.ClearProjectError();
                return result;
            }
        }

        public bool CreateFromXML(string XMLData)
        {
            Clear();
            try
            {
                mvarAppendToPrevious = cXml.ExtractBool(XMLData, "<AppendToPrev>", "</AppendToPrev>");
                mvarExportCondSpecific = cXml.ExtractBool(XMLData, "<ExportCondSpecific>", "</ExportCondSpecific>");
                mvarExportWhenRTF = cXml.ExtractBool(XMLData, "ExportWhenRTF");
                mvarExportWhenRTFChapters = cXml.ExtractBool(XMLData, "ExportWhenRTFChapters");
                mvarExportWhenHTML = cXml.ExtractBool(XMLData, "<ExportWhenHTML>", "</ExportWhenHTML>");
                mvarExportWhenText = cXml.ExtractBool(XMLData, "<ExportWhenText>", "</ExportWhenText>");
                mvarExportWhenLaTeX = cXml.ExtractBool(XMLData, "<ExportWhenLaTeX>", "</ExportWhenLaTeX>");
                mvarWordCount = cXml.ExtractInt(XMLData, "<WordCount>", "</WordCount>");
                mvarLetterCount = cXml.ExtractInt(XMLData, "<LetterCount>", "</LetterCount>");
                mvarV6 = cXml.ExtractBool(XMLData, "V6");
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                Exception ex2 = ex;
                ProjectData.ClearProjectError();
            }

            return UpdateFromXML(XMLData, ResetID: false, TriggerSaveEvent: false);
        }

        internal bool UpdateFromXML(string XMLData, bool ResetID, bool TriggerSaveEvent)
        {
            bool result = false;
            try
            {
                string[] DataArray = new string[2];
                if (!BaseCreateFromXML(XMLData))
                {
                    return result;
                }

                SpecificDateMode = cXml.ExtractBool(XMLData, "<SpecificDateMode>", "</SpecificDateMode>");
                if (SpecificDateMode)
                {
                    SpecificDateTime = cXml.ExtractDate(XMLData, "<SpecificDateTime>", "</SpecificDateTime>");
                }

                mvarOutcome = cXml.ExtractCData(XMLData, "<Outcome>", "</Outcome>");
                mvarGoal = cXml.ExtractCData(XMLData, "<Goal>", "</Goal>");
                mvarConflict = cXml.ExtractCData(XMLData, "<Conflict>", "</Conflict>");
                mvarRTFFile = cXml.ExtractCData(XMLData, "<RTFFile>", "</RTFFile>");
                mvarBelongsToChID = cXml.ExtractInt(XMLData, "<BelongsToChID>", "</BelongsToChID>");
                mvarMinute = cXml.ExtractInt(XMLData, "<Minute>", "</Minute>");
                mvarHour = cXml.ExtractInt(XMLData, "<Hour>", "</Hour>");
                mvarDay = cXml.ExtractInt(XMLData, "<Day>", "</Day>");
                mvarLastsMinutes = cXml.ExtractInt(XMLData, "<LastsMinutes>", "</LastsMinutes>");
                mvarLastsHours = cXml.ExtractInt(XMLData, "<LastsHours>", "</LastsHours>");
                mvarLastsDays = cXml.ExtractInt(XMLData, "<LastsDays>", "</LastsDays>");
                mvarReactionScene = cXml.ExtractBool(XMLData, "<ReactionScene>", "</ReactionScene>");
                mvarSubplot = cXml.ExtractBool(XMLData, "<SubPlot>", "</SubPlot>");
                mvarStatus = cXml.ExtractInt(XMLData, "<Status>", "</Status>");
                if (mvarWordCount == 0)
                {
                    UpdateCount = true;
                }
                else
                {
                    UpdateCount = false;
                }

                int num = 1;
                do
                {
                    mvarField[num] = cXml.ExtractInt(XMLData, "<Field" + Conversions.ToString(num) + ">",
                        "</Field" + Conversions.ToString(num) + ">");
                    if (mvarField[num] == 0)
                    {
                        mvarField[num] = 1;
                    }

                    num++;
                } while (num <= 4);

                cXml.ExtractXMLArray(XMLData, "<Characters>", "</Characters>", "</CharID>", ref DataArray);
                int num2 = DataArray.Length - 1;
                for (num = 0; num <= num2; num++)
                {
                    if (Strings.InStr(1, DataArray[num], "<CharID>", CompareMethod.Text) > 0)
                    {
                        int num3 = cXml.ExtractInt(DataArray[num], "<CharID>", "</CharID>");
                        CharIDs.Add(num3, Conversions.ToString(num3));
                    }
                }

                cXml.ExtractXMLArray(XMLData, "<Locations>", "</Locations>", "</LocID>", ref DataArray);
                int num4 = DataArray.Length - 1;
                for (num = 0; num <= num4; num++)
                {
                    if (Strings.InStr(1, DataArray[num], "<LocID>", CompareMethod.Text) > 0)
                    {
                        int num5 = cXml.ExtractInt(DataArray[num], "<LocID>", "</LocID>");
                        LocIDs.Add(num5, Conversions.ToString(num5));
                    }
                }

                cXml.ExtractXMLArray(XMLData, "<Items>", "</Items>", "</ItemID>", ref DataArray);
                int num6 = DataArray.Length - 1;
                for (num = 0; num <= num6; num++)
                {
                    if (Strings.InStr(1, DataArray[num], "<ItemID>", CompareMethod.Text) > 0)
                    {
                        int num7 = cXml.ExtractInt(DataArray[num], "<ItemID>", "</ItemID>");
                        ItemIDs.Add(num7, Conversions.ToString(num7));
                    }
                }

                if (mvarV6)
                {
                    string markup = cXml.ExtractCData(XMLData, "SceneContent");
                    SetMarkup(markup);
                }
                else
                {
                    string text = cXml.ExtractBetweenTags(XMLData, "<EMBEDDEDRTF>", "</EMBEDDEDRTF>");
                    if (Operators.CompareString(text, "", TextCompare: false) != 0)
                    {
                        TextRTF = cXml.ExtractBetweenTags(text, "<![CDATA[", "]]>");
                    }
                    else
                    {
                        TextRTF = "";
                    }
                }

                result = true;
                return result;
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                Exception ex2 = ex;
                clsShared.cLog.AddAction(ex2, MethodBase.GetCurrentMethod());
                ProjectData.ClearProjectError();
                return result;
            }
        }

        public virtual bool LoadRTFV5(string Projectpath)
        {
            return false;
        }

        public bool ContainsCharID(int ID)
        {
            return CharIDs.Contains(ID);
        }

        public bool ContainsItemID(int ID)
        {
            return ItemIDs.Contains(ID);
        }

        public bool ContainsLocID(int ID)
        {
            return LocIDs.Contains(ID);
        }

        public bool FileIsClosed()
        {
            bool flag = true;
            try
            {
                if (!clsShared.cFile.FileExists(mvarRTFFile))
                {
                    return true;
                }

                FileStream fileStream = File.Open(mvarRTFFile, FileMode.Append, FileAccess.Write, FileShare.None);
                flag = (fileStream.CanWrite ? true : false);
                fileStream.Close();
                return flag;
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                Exception ex2 = ex;
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
            }
        }

        public void RemoveAllChar()
        {
            CharIDs.Clear();
        }

        public void RemoveAllLoc()
        {
            LocIDs.Clear();
        }

        public void RemoveAllItems()
        {
            ItemIDs.Clear();
        }

        public void ForceNewRTFFile()
        {
            RTFNeedsSaving = true;
            mvarRTFFile = "";
        }

        public bool CloneTo(ref clsScene NewScene)
        {
            try
            {
                NewScene = (clsScene) MemberwiseClone();
                NewScene.ForceNewRTFFile();
                return true;
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                Exception ex2 = ex;
                bool result = false;
                NewScene = null;
                clsShared.cLog.AddAction(ex2, MethodBase.GetCurrentMethod());
                ProjectData.ClearProjectError();
                return result;
            }
        }

        public virtual bool SaveRTFV5(string ProjectPath)
        {
            _ = mvarV6;
            return true;
        }
    }
}